<!DOCTYPE html>
<html lang="en">

  <head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
  </head>

  <body>
    <script>
      /*  
            借用构造函数实现的继承，无法实现访的复用

            还要借助另一个方式：

            原型继承
                --  解决 方法的复用

            做法：
                小分类的 构造函数.prototype = 大分类的实例
        */

      function Person(name, age, gender) {
        this.name = name
        this.age = age
        this.gender = gender
      }

      Person.prototype.sayHi = function () {
        console.log('hello !!!');
      }

      function Teacher(name, age, gender, salary) {
        Person.call(this, name, age, gender)
        this.salary = salary
      }
      // 原型继承
      Teacher.prototype = new Person()
      // 把原型关系补全
      Teacher.prototype.constructor = Teacher
      // 再给Teacher的原型加方法
      Teacher.prototype.teach = function () {
        console.log('今天讲继承');
      }


      function Student(name, age, gender, number) {
        Person.call(this, name, age, gender) // 借用构造函数
        this.number = number
      }
      // 原型继承
      Student.prototype = new Person()
      // 把原型关系补全
      Student.prototype.constructor = Student

      let s1 = new Student('狗蛋', 12, '男')
      s1.sayHi()
      console.log(s1);


      /*
          把结合借用构造函数 + 原型继承称为:组合继承
      */
    </script>
  </body>

</html>